﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonInteractive
{

    public static class HelperCommonInteractive
    {

        #region Is

        /// <summary>
        /// Istypes the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="searchtype">The searchtype.</param>
        /// <returns></returns>
        public static bool Is(this Type type, Type searchtype)
        {
            if (type == null || searchtype == null)
                return false;

            if (searchtype.IsClass)
                return type == searchtype || type.IsSubclassOf(searchtype);
            else if (searchtype.IsInterface)
                return (type.GetInterface(searchtype.FullName, true) != null);
            return false;
        }


        public static bool Is(this Type type, params Type[] searchtypes)
        {

            foreach (Type searchtype2 in searchtypes)
                if (Is(type, searchtype2))
                    return true;

            return false;
        }

        #endregion

    }
}
